#
# matplotlib支持一些基础的三维图表绘制，比如曲面图、散点图和柱状图，需要使用mpl_toolkits模块。
#

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt


def plt3d_cure():
    #
    ax = plt.subplot(projection='3d')

    # 生成测试数据
    theta = np.linspace(-4*np.pi, 4*np.pi, 100)
    z = np.linspace(-4, 4, 100)*0.3
    r = z**4 + 1
    x = r*np.sin(theta)
    y = r*np.cos(theta)

    # 三维曲线图：根据测试数据x、y、z，然后绘制三维曲线，并设置图例字号
    ax.plot(x, y, z, 'b^-', label='3D Picture Test')
    mpl.rcParams['legend.fontsize'] = 10
    ax.legend()
    plt.show()
    return


def plt3d_bar():
    #
    x = np.random.randint(0, 40, 10)
    y = np.random.randint(0, 40, 10)
    z = 80*abs(np.sin(x + y))

    ax = plt.subplot(projection='3d')

    for xx, yy, zz in zip(x, y, z):
        color = np.random.random(3)
        ax.bar3d(xx, yy, 0, dx=1, dy=1, dz=zz, color=color)

    ax.set_xlabel('X')
    ax.set_xlabel('Y')
    ax.set_xlabel('Z')

    plt.show()
    return


# main
def main():
    # plt3d_cure()
    plt3d_bar()
    return


if __name__ == '__main__':
    main()
